package first.group.ssh.packet;

import first.group.ssh.SSHConsts;
import first.group.ssh.packet.reader.BigIntegerReader;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.ByteBuffer;

public class DiffieHellmanGroupExchangeGroupPacket extends Packet {
    
    public final BigInteger p, g;

    public DiffieHellmanGroupExchangeGroupPacket(BigInteger p, BigInteger g) {
        super(SSHConsts.SSH_MSG_KEX_DH_GEX_GROUP);
        this.p = p;
        this.g = g;
    }
    
    public static PacketParser<DiffieHellmanGroupExchangeGroupPacket> PARSER = new Parser();

    private static class Parser extends PacketParser<DiffieHellmanGroupExchangeGroupPacket> {

        @Override
        public DiffieHellmanGroupExchangeGroupPacket parse(ByteBuffer buffer) throws IOException {
            var p = BigIntegerReader.readBigInteger(buffer);
            if (p == null) {
                return null;
            }
            var g = BigIntegerReader.readBigInteger(buffer);
            if (g == null) {
                return null;
            }
            return new DiffieHellmanGroupExchangeGroupPacket(p, g);
        }
    }

    @Override
    public void write(ByteBuffer buffer) {
        throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
    }

    @Override
    public String toString() {
        return "DiffieHellmanGroupExchangeGroupPacket{" + "p=" + p + ", g=" + g + '}';
    }
}
